package cn.work.service;

import cn.work.bean.reservationBean;
import cn.work.dao.reservaDao;

import java.sql.SQLException;
import java.util.List;

public class ReservationService {

    private reservaDao reservationDAO = new reservaDao();

    public boolean processReservationAction(int reservationId, String action) throws SQLException {
        switch (action) {
            case "completed":
                return updateReservationState(reservationId, "已完成");
            case "canceled":
                return updateReservationState(reservationId, "已取消");
            case "deleted":
                return deleteReservation(reservationId);
            default:
                // 如果 action 无效，返回 false
                return false;
        }
    }

    private boolean updateReservationState(int reservationId, String state) throws SQLException {
        return reservationDAO.updateState(reservationId, state);
    }

    private boolean deleteReservation(int reservationId) throws SQLException {
        return reservationDAO.delete(reservationId);
    }

    public boolean processReservationAction(reservationBean reservation, String action) throws SQLException {
        return reservationDAO.insert(reservation);
    }

    public List<reservationBean> getReservationListService(int user_id) throws SQLException {
        return reservationDAO.getReserByUserId(user_id);
    }

    public List<reservationBean> searchReservations(String search) throws SQLException {
        return reservationDAO.search(search);
    }

    public List<reservationBean> getAllReservation() throws SQLException {
        return reservationDAO.getAll();
    }
}
